package com.nengchuan.kbms.dfs.controller.work;


import com.nengchuan.excel.util.CsncExcelUtil;
import com.nengchuan.kbms.dfs.entity.dto.UserMessagePageDTO;
import com.nengchuan.kbms.dfs.entity.vo.UserMessageVO;
import com.nengchuan.kbms.dfs.service.UserMessageService;
import com.nengchuan.model.model.NcPageInfo;
import com.nengchuan.model.model.WrappedResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 用户消息 前端控制器
 * </p>
 *
 * @author abe
 * @since 2020-03-30
 */
@RestController
@RequestMapping("/work/message")
@Api(tags = "知识库数据后台管理 > 工作管理 > 我的消息 【已完成】")
public class MessageController {

    @Autowired
    private UserMessageService userMessageService;

    @GetMapping("/data")
    @ApiOperation(value = "查询")
    public WrappedResult<UserMessageVO> data(@RequestParam Long id) {
        UserMessageVO userMessageVO = userMessageService.getById(id, UserMessageVO.class);
        return WrappedResult.success(userMessageVO);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public WrappedResult<Boolean> delete(@ApiParam(value = "消息id", required = true) @RequestParam Serializable id) {
        return WrappedResult.success(userMessageService.remove(id));
    }

    @PostMapping("/page")
    @ApiOperation(value = "列表")
    public WrappedResult<NcPageInfo<UserMessageVO>> page(@RequestBody UserMessagePageDTO pageDTO) {
        return WrappedResult.success(userMessageService.page(pageDTO, UserMessageVO.class));
    }

    @PostMapping(value = "/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @ApiOperation(value = "导出列表")
    public void export(@RequestBody UserMessagePageDTO pageDTO, HttpServletResponse response) throws Exception {
        List<UserMessageVO> list = userMessageService.list(pageDTO, UserMessageVO.class);
        CsncExcelUtil.export(list, UserMessageVO.class, response, "我的消息列表.xls");
    }

}
